package com.sws.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sws.mapping.BannerMapper;
import com.sws.mapping.NewsMapper;
import com.sws.model.bean.B2SBannerPageBean;
import com.sws.model.bean.B2SNewsPageBean;
import com.sws.service.PushService;

@Service
public class PushServiceImpl implements PushService {
	
	@Autowired
	private BannerMapper bannerMapper;
	@Autowired
	private NewsMapper newsMapper;

	@Override
	public List getAllBanner(B2SBannerPageBean bean) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("skips", (bean.getPages()-1)*bean.getLimits());
		map.put("limits", bean.getLimits());
		map.put("des", bean.getDes());
		if (bean.getTime() != null) {
			map.put("startTime", new Date(bean.getTime().getYear(), bean.getTime().getMonth(), bean.getTime().getDate(), 0, 0, 0));
			map.put("endTime", new Date(bean.getTime().getYear(), bean.getTime().getMonth(), bean.getTime().getDate(), 23, 59, 59));
		}
		return bannerMapper.getAllBanner(map);
	}

	@Override
	public List getAllNews(B2SNewsPageBean bean) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("skips", (bean.getPages()-1)*bean.getLimits());
		map.put("limits", bean.getLimits());
		map.put("title", bean.getTitle());
		if (bean.getTime() != null) {
			map.put("startTime", new Date(bean.getTime().getYear(), bean.getTime().getMonth(), bean.getTime().getDate(), 0, 0, 0));
			map.put("endTime", new Date(bean.getTime().getYear(), bean.getTime().getMonth(), bean.getTime().getDate(), 23, 59, 59));
		}
		return newsMapper.getAllNews(map);
	}

}
